#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
    vector<int> maxInWindows(const vector<int>& num, unsigned int size)
    {
        vector<int> output;
        if(num.size() == 0 || size == 0 || num.size() < size)
        	return output;
    	if(num.size() < size)
		{
			output.push_back(maxCal(num));
			return output;
		}
        auto in = num.begin() + size,out = num.begin();

		int max = maxCal(vector<int>(out,in));
        while(in != num.end())
        {
        	output.push_back(max);
        	if(*in >= max)
        		max = *in;
        	else if(*out == max)
    			max = maxCal(vector<int>(out+1,in+1));
        	++in;
        	++out;
        }
        max = maxCal(vector<int>(out,in));
        output.push_back(max);
        return output;
    }

    int maxCal(const vector<int> &num)
    {
    	int max = num[0];
    	for(unsigned int i = 1; i != num.size();++i)
    		if(max < num[i])
    			max = num[i];
    	return max;
    }

    void printV(const vector<int> &n)
    {
    	for(int i: n )
    		cout<<i<<",";
    	cout<<endl;
    }

};

int main()
{
	vector<int> n{2,3,4,2,6,2,5,1};
	vector<int> n1{16,14,12,10,8,6,4};
	Solution s;
	vector<int> win = s.maxInWindows(n1,5);
	s.printV(win);
	return 0;
}